package com.sinaapp.aidaka.server.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;

import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import com.sinaapp.aidaka.server.config.ConfigManager;
import com.sinaapp.aidaka.server.utils.ConnectionFactory;

public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = -4777712363997682800L;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		
		String realPath = getServletContext().getRealPath("/");
		String confPath = getInitParameter("configPath");
		String configPath = realPath + confPath;
		ConfigManager.I.init(configPath);
		
		WebApplicationContext context=ContextLoaderListener.getCurrentWebApplicationContext();
		ConnectionFactory.I.init((DataSource) context.getBean("dataSource"));
	}
}
